package logic

import (
	"context"
	"hema-fresh/hemarpc/models/mysql"

	"hema-fresh/hemarpc/hemarpc"
	"hema-fresh/hemarpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HemaTypeAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHemaTypeAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HemaTypeAddLogic {
	return &HemaTypeAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 分类添加
func (l *HemaTypeAddLogic) HemaTypeAdd(in *hemarpc.HemaTypeAddRequest) (*hemarpc.HemaTypeAddResponse, error) {
	// todo: add your logic here and delete this line

	types := mysql.HemaType{
		TypeName: in.TypeName,
	}
	if err := types.HemaTypeAdd(mysql.DB); err != nil {
		return nil, err
	}
	return &hemarpc.HemaTypeAddResponse{
		HemaTypeId: int64(types.ID),
	}, nil
}
